package br.jus.cnj.report;

import javax.faces.context.FacesContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;

public class GerarRelatorioXLSX implements GerarRelatorio {
	
	protected GerarRelatorioXLSX() {
	}

	public void gerarRelatorio(JasperPrint jasperPrint, String nomeRelatorio) throws Exception {
		HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
		httpServletResponse.addHeader("Content-disposition", "attachment; filename=" + nomeRelatorio + ".xlsx");
		ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
		JRXlsxExporter docxExporter = new JRXlsxExporter();
		docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
		docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);
		docxExporter.exportReport();
		FacesContext.getCurrentInstance().responseComplete();
	}

}
